AS := as
LD := ld

.s.o:
	@echo -n ""

all: boot.bin 2ndstage.bin

boot.bin: boot.out
	objcopy -O binary -j .text boot.out boot.bin

boot.out: boot.o
	$(LD) -o boot.out boot.o -Ttext 0x7c00

boot.o: boot.s bootsector.s functions.s macros.s
	$(AS) -o boot.o boot.s

2ndstage.bin: 2ndstage.out
	objcopy -O binary -j .text 2ndstage.out 2ndstage.bin

2ndstage.out: 2ndstage.o
	$(LD) -o 2ndstage.out 2ndstage.o -Ttext 0x0

2ndstage.o: 2ndstage.s bootsector.s functions.o macros.s
	$(AS) -o 2ndstage.o 2ndstage.s

test.img: boot.bin 2ndstage.bin
	imagefs c test.img 720
	imagefs b test.img boot.bin
	imagefs a test.img 2ndstage.bin

clean:
	rm -f *.o *.out *.bin
